package com.youdianda.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youdianda.entity.SysMenu;
import com.youdianda.vo.MenuQueryVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 菜单表 Mapper 接口
 * </p>
 *
 * @author mosen
 * @since 2023-05-15
 */
@Mapper
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    /**所有菜单*/
    @Select("select * from sys_menu where pid=#{id}")
    List<SysMenu> selectMenusByPidAndMenuQueryVOId(MenuQueryVO menuQueryVO);

    /**添加菜单*/
    @Insert("insert into sys_menu (pid,path,component,title,icon,is_show,is_cache,is_link,redirect,create_date,update_date,del_flag,type,sort,mark,default_data) values (#{pid},#{path},#{component},#{title},#{icon},#{isShow},#{isCache},#{isLink},#{redirect},#{createDate},#{updateDate},#{delFlag},#{type},#{sort},#{mark},#{defaultData})")
    void addMenu(SysMenu sysMenu);

    /**菜单详情*/
    @Select("select * from sys_menu where id=#{id}")
    SysMenu getMenuById(Integer id);

    /**菜单修改*/
    @Update("update sys_menu set pid=#{pid},path=#{path},component=#{component},title=#{title},icon=#{icon},is_show=#{isShow},is_cache=#{isCache},is_link=#{isLink},redirect=#{redirect},update_date=#{updateDate},del_flag=#{delFlag},type=#{type},sort=#{sort},mark=#{mark},default_data=#{defaultData} where id=#{id}")
    void updateMenu(SysMenu sysMenu);

    /**递归获取子ids*/
    @Select("select id from sys_menu where pid=#{id}")
    List<Integer> getIdsByPid(Integer id);

    /**根据id和pid查找*/
    @Select("select id from sys_menu where id=#{i} and pid=#{pid}")
    Integer getMenuByIdAndPid(int i, int pid);
}
